#include <stdio.h>
#include <stdlib.h>
#include <csp_spu.h>
#include <csp_debug.h>

int global_pid; 


int Run(){
	int res = 0;
	int pid = csp_pid();

	global_pid = csp_pid();

	char *recursive_task = "150_parallel_processes_task"; 

	csp_process n150_recursive_tasks[] = {
		csp_create_process(recursive_task),
		csp_create_process(recursive_task),
		csp_create_process(recursive_task),
		csp_create_process(recursive_task),
		csp_create_process(recursive_task) };


	if( csp_pid() < 130 ){
		csp_run_parallel(n150_recursive_tasks, 5);
	}else if( csp_pid() == 150 ){
		res = csp_pid();
	}

	ASSERT( pid == csp_pid() );
	ASSERT( global_pid == csp_pid() );

	PRINTF_FOR_TESTING("%s terminating on spe #%i with pid %i\n",__FILE__ , csp_spe_id(), pid);

	PRINTF_FOR_TESTING("Nested task with pid=%i terminated with res=%i.\n", pid, res);

	return res;
}
